﻿package com.alstudio.module.sns.weiboshare;


public final class WeiboShareImageCreator {/*
	private static final String TAG = "WeiboShareImageCreator";

	public static Bitmap createShareImage() {
		final int avatar_bg_x = 40;
		final int avatar_bg_width = 140;
		final int avatar_bg_height = 140;
		final int avatar_bg_padding = 10;

		final int avatar_x = avatar_bg_x + avatar_bg_padding;
		final int avatar_width = avatar_bg_width - avatar_bg_padding * 2;
		final int avatar_height = avatar_bg_height - avatar_bg_padding * 2;

		final int nickname_x = avatar_bg_x + avatar_bg_width + 10;

		final int id_bg_x = nickname_x;
		final int id_bg_round_width = 11;
		final int id_bg_height = 19;
		final int id_bg_padding = 8;

		final int id_x = id_bg_x + id_bg_round_width + id_bg_padding;

		final int nick_text_size = 27;
		final int id_text_size = 15;

		// 创建Bitmap
		Bitmap avatar = createMyAvatarImage();
		Bitmap share_image_bg = createImageFromResource(R.drawable.weibo_share_image_id_bg1);
		Bitmap avatar_bg = createImageFromResource(R.drawable.weibo_share_image_avatar_bg);
		Bitmap id_bg1 = createImageFromResource(R.drawable.weibo_share_image_id_bg1);
		Bitmap id_bg2 = createImageFromResource(R.drawable.weibo_share_image_id_bg2);
		Bitmap id_bg3 = createImageFromResource(R.drawable.weibo_share_image_id_bg3);

		Bitmap bitmap = null;

		if (share_image_bg != null) {
			bitmap = share_image_bg;
			if (!bitmap.isMutable()) {
				bitmap = share_image_bg.copy(Bitmap.Config.RGB_565, true);
			}

			Paint paint = new Paint();
			Canvas canvas = new Canvas(bitmap);

			final int avatar_bg_y = (bitmap.getHeight() - avatar_bg_height) / 2;
			final int avatar_y = avatar_bg_y + avatar_bg_padding;

			Rect srcRect = new Rect();
			Rect dstRect = new Rect();
			// 画头像边框
			if (avatar_bg != null) {
				srcRect.set(0, 0, avatar_bg.getWidth(), avatar_bg.getHeight());
				dstRect.set(avatar_bg_x, avatar_bg_y, avatar_bg_x
						+ avatar_bg_width, avatar_bg_y + avatar_bg_height);

				canvas.drawBitmap(avatar_bg, srcRect, dstRect, paint);
			}

			// 画头像
			if (avatar != null) {
				srcRect.set(0, 0, avatar.getWidth(), avatar.getHeight());
				dstRect.set(avatar_x, avatar_y, avatar_x + avatar_width,
						avatar_y + avatar_height);
				canvas.drawBitmap(avatar, srcRect, dstRect, paint);
			}

			paint.setColor(Color.WHITE);// 设置字体大小
			paint.setTypeface(Typeface.DEFAULT);// 设置字体类型
			paint.setAntiAlias(true); // 抗锯齿

			// 画昵称
			String nickname = App.myVcard.getNick();
			if (!TextUtils.isEmpty(nickname)) {
				paint.setTextSize(nick_text_size);// 设置字体大小

				int nickname_y = avatar_y + nick_text_size + 20;
				canvas.drawText(nickname, nickname_x, nickname_y, paint);
			}

			// 画JID
			String id = App.myVcard.getIdFromJid();
			if (!TextUtils.isEmpty(id)) {
				id = "ID : " + id;

				paint.setTextSize(id_text_size);// 设置字体大小

				int height = getFontHeight(id_text_size);
				final int id_bg_y = avatar_bg_y + avatar_bg_height
						- id_bg_height - 40;

				FontMetrics fm = paint.getFontMetrics();
				final int id_y = id_bg_y + id_bg_height
						- (id_bg_height - height) / 2 - (int) fm.descent - 2;

				// 画JID边框
				if (id_bg1 != null && id_bg2 != null && id_bg3 != null) {
					int text_width = (int) paint.measureText(id);

					int x1, x2;
					int bottom = id_bg_y + id_bg_height;

					// 左边
					x1 = id_bg_x;
					x2 = x1 + id_bg_round_width;
					srcRect.set(0, 0, id_bg1.getWidth(), id_bg1.getHeight());
					dstRect.set(x1, id_bg_y, x2, bottom);
					canvas.drawBitmap(id_bg1, srcRect, dstRect, paint);

					// 中间
					x1 = x2;
					x2 = x1 + text_width + id_bg_padding * 2;
					srcRect.set(0, 0, id_bg2.getWidth(), id_bg2.getHeight());
					dstRect.set(x1, id_bg_y, x2, bottom);
					canvas.drawBitmap(id_bg2, srcRect, dstRect, paint);

					// 右边
					x1 = x2;
					x2 = x1 + id_bg_round_width;
					srcRect.set(0, 0, id_bg3.getWidth(), id_bg3.getHeight());
					dstRect.set(x1, id_bg_y, x2, bottom);
					canvas.drawBitmap(id_bg3, srcRect, dstRect, paint);
				}

				// 画JID
				canvas.drawText(id, id_x, id_y, paint);
			}

			canvas.save(Canvas.ALL_SAVE_FLAG);
			// 存储新合成的图片
			canvas.restore();
		}

		return bitmap;
	}

	private static Bitmap createImageFromResource(int resId) {
		Bitmap image = null;
		Drawable drawable = App.ctx.getResources().getDrawable(resId);

		if (drawable != null) {
			image = ((BitmapDrawable) drawable).getBitmap();
		}

		return image;
	}

	private static Bitmap createMyAvatarImage() {
		Bitmap image = null;

		// 取大头像
		String fileId = App.myVcard.getAvatar();
		if (!TextUtils.isEmpty(fileId)) {
			String s = null;
			s = App.getLocalFileByFileId(App.ICON_PATH, fileId);

			if (!TextUtils.isEmpty(s)) {
				ALLog.d("取大头");

				try {
					image = BitmapUtil.decodeFile(s,
							BitmapUtil.DEFAULT_SAMPLE_SIZE_2);

				} catch (Exception e) {
					image = null;
				}
			}
		}

		// 取小头像
		if (image == null) {
			fileId = App.myVcard.getThumbAvatar();
			if (!TextUtils.isEmpty(fileId)) {

				String s = null;
				s = App.getLocalFileByFileId(App.ICON_PATH, fileId);

				if (!TextUtils.isEmpty(s)) {
					ALLog.d("取小头");
					try {
						image = BitmapUtil.decodeFile(s,
								BitmapUtil.DEFAULT_SAMPLE_SIZE_2);

					} catch (Exception e) {
						image = null;
					}
				}
			}
		}

		// 取默认头像
		if (image == null) {
			ALLog.d("没头");
			image = createImageFromResource(FileUtil.getMyHeadIcon());
		}

		return image;
	}

	private static int getFontHeight(float fontSize) {
		Paint paint = new Paint();
		paint.setTextSize(fontSize);
		FontMetrics fm = paint.getFontMetrics();
		return (int) Math.ceil(fm.descent - fm.top) + 2;
	}
*/}
